package xuwei_k

object DB{
  import com.google.appengine.api.datastore._
  import scala.collection.JavaConversions._
  
  private val entityKey = "git-commit-id"
  private val propertyName = "id"
    
  val ds = DatastoreServiceFactory.getDatastoreService
  
  def insert(commitIds:CommitId*){
    val d = new java.util.Date()
    commitIds.foreach{c =>
      val e = new Entity(entityKey)
      e.setProperty(propertyName, c.id )
      e.setProperty("created-date",d)
      ds.put(e)
    }
  }
    
  def selectAll:Seq[CommitId] = {
    ds.prepare(new Query(entityKey)).asIterable.map{
      e =>
      CommitId.apply(e.getProperty(propertyName).asInstanceOf[String])
    }.toSeq
  }

}